package com.hctforgreen.greenservice.utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class DataVersionCodeUtil {
	public static void save(Activity activity, String versionCode) {
		SharedPreferences sharedPreferences = activity.getSharedPreferences(
				HctConstants.DATA_VERSION_CODE_STORE_FILE_NAME,
				Context.MODE_WORLD_WRITEABLE);
		Editor editor = sharedPreferences.edit();

		editor.putString(HctConstants.DATA_VERSION_CODE_STORE_KEY_VALUE,
				versionCode);
		editor.commit();
	}

	public static String get(Activity activity) {
		SharedPreferences sharedPreferences = activity.getSharedPreferences(
				HctConstants.DATA_VERSION_CODE_STORE_FILE_NAME,
				Context.MODE_WORLD_WRITEABLE);
		String versionCode = sharedPreferences.getString(HctConstants.DATA_VERSION_CODE_STORE_KEY_VALUE, "");
		return versionCode;
	}
	
	/*
	 * 20160607
	 * 390694--添加
	 * 书籍资料版本号存储本地
	 */
	public static void saveBookVersion(Context activity, String versionCode) {
		SharedPreferences sharedPreferences = activity.getSharedPreferences(
				HctConstants.BOOK_DATA_VERSION_CODE_STORE_FILE_NAME,
				Context.MODE_WORLD_WRITEABLE);
		Editor editor = sharedPreferences.edit();

		editor.putString(HctConstants.BOOK_DATA_VERSION_CODE_STORE_KEY_VALUE,
				versionCode);
		editor.commit();
	}
	
	/*
	 * 20160607
	 * 390694--添加
	 * 书籍资料版本号本地获取
	 */
	public static String getBookVersion(Activity activity) {
		SharedPreferences sharedPreferences = activity.getSharedPreferences(
				HctConstants.BOOK_DATA_VERSION_CODE_STORE_FILE_NAME,
				Context.MODE_WORLD_WRITEABLE);
		String versionCode = sharedPreferences.getString(HctConstants.BOOK_DATA_VERSION_CODE_STORE_KEY_VALUE, "");
		return versionCode;
	}
}
